﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using SES.CMS.DO;
using SES.CMS.BL;
using System.Data;

namespace SES.CMS
{
    public partial class Search : System.Web.UI.Page
    {
        cmsProductBL data = new cmsProductBL();
        cmsProductDO itemProductDO = new cmsProductDO();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                string keyWord = Request.QueryString["ID"];
                if (!IsPostBack)
                {
                    if (Session["shop"] == null)
                    {
                        Session["shop"] = new MyShopCart();
                    }
                    SEO(keyWord);
                }
                SimpleSearch(keyWord);
            }
            else
            {
                Response.Redirect("/Default.aspx");
            }
        }
        public string domain()
        {
            return Ultility.TopbikeDomain();
        }
        protected void SEO(string keyWord)
        {
            //SEO
            Page.Title = keyWord + " | " + Ultility.WebTitle();

            sysConfigDO objConfig = new sysConfigDO();
            objConfig.ConfigID = 2;

            objConfig = new sysConfigBL().Select(objConfig);


            HtmlMeta metaKey = new HtmlMeta();
            metaKey.Name = "keywords";
            metaKey.Content = objConfig.ConfigValue;
            Page.Header.Controls.Add(metaKey);

            objConfig.ConfigID = 3;
            objConfig = new sysConfigBL().Select(objConfig);
            HtmlMeta metaDesc = new HtmlMeta();
            metaDesc.Name = "description";
            metaDesc.Content = objConfig.ConfigValue;
            Page.Header.Controls.Add(metaDesc);
        }
        private void LoadPromotionProduct(DataTable dt)
        {
            CollectionPager1.MaxPages = 10000;

            CollectionPager1.PageSize = 28; // số items hiển thị trên một trang

            CollectionPager1.DataSource = dt.DefaultView;

            CollectionPager1.BindToControl = rptNewProduct;
            rptNewProduct.DataSource = CollectionPager1.DataSourcePaged;
            rptNewProduct.DataBind();
        }

        private void SimpleSearch(string keyword)
        {
            LoadPromotionProduct(new cmsProductBL().SimpleSearch(keyword));
        }
        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
        public string WordCut(string text)
        {
            return Ultility.WordCut(text, 260, new char[] { ' ', '.', ',', ';' }) + "...";
        }

    }
}